package com.braveman.im.ui.adapter;

import android.graphics.drawable.Drawable;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.widget.ImageView;
import android.widget.TextView;

import com.braveman.im.R;
import com.braveman.im.bean.DataListBean;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class GroupListMemberAdapter extends BaseQuickAdapter<DataListBean, BaseViewHolder> {
    private Drawable drawable;

    public GroupListMemberAdapter(@LayoutRes int layoutResId, @Nullable List<DataListBean> data) {
        super(R.layout.item_group_member, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, DataListBean item) {
        boolean isShow = false;
        boolean isShowManager = false;
        switch (item.groupRole) {
            case "owner":
                isShow = true;
                isShowManager = false;
                break;
            case "admin":
                isShow = false;
                isShowManager = true;
                break;
            case "member":
                isShow = false;
                isShowManager = false;
                break;
        }
        helper.setGone(R.id.iv_group_manager_head, isShow).setGone(R.id.iv_group_manager_name, isShowManager);
        ImageView mIvItemHeadIcon = helper.getView(R.id.iv_item_head_icon);
        TextView mTvItemName = helper.getView(R.id.tv_item_name);
        TextView mTvItemDes = helper.getView(R.id.tv_item_des);
        TextView mTvItemHeadName = helper.getView(R.id.tv_item_head_name);
        mTvItemName.setText(item.memberName);
        mTvItemDes.setText(item.groupRoleDescription);
        mTvItemHeadName.setText(item.memberImUsername);
        if (item.memberAvatar != null) {
            Glide.with(mContext)//
                    .load(item.memberAvatar)//
                    .into(mIvItemHeadIcon);
        }

        switch (item.memberIntegrityIndex) {
            case 1:
                drawable = mContext.getResources().getDrawable(R.mipmap.group_icon_star_1x);
                break;
            case 2:
                drawable = mContext.getResources().getDrawable(R.mipmap.group_icon_star_2);
                break;
            case 3:
                drawable = mContext.getResources().getDrawable(R.mipmap.group_icon_star_3);
                break;
            case 4:
                drawable = mContext.getResources().getDrawable(R.mipmap.group_icon_star_4);
                break;
            case 5:
                drawable = mContext.getResources().getDrawable(R.mipmap.group_icon_star_5);
                break;
            default:
                drawable = mContext.getResources().getDrawable(R.mipmap.group_icon_star_5);
        }
        drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight()); //设置边界
        mTvItemName.setCompoundDrawables(null, null, drawable, null);//画在右边

    }
}
